package reggie.ruiji.mapper;

import org.apache.ibatis.annotations.*;
import reggie.ruiji.Dto.SetmealDto;
import reggie.ruiji.pojo.Dish;
import reggie.ruiji.pojo.Setmeal;

import java.util.List;

@Mapper
public interface SetmealMapper
{
    @Select("select count(*) from setmeal where category_id = #{id}")
    public Long countByid (Long id);


    @Insert("insert into setmeal (name,category_id,price,status,description,image,create_time, update_time, create_user, update_user, code)" +
            " values (#{name},#{categoryId},#{price},#{status},#{description},#{image},#{createTime}, #{updateTime}, #{createUser}, #{updateUser}, #{code})")
    public void insert(Setmeal  setmeal);


    @Select("select id from setmeal where name = #{name}")
    public Long getIdByName(String name);


    @Results({
            @Result(column = "category_id", property = "categoryId"),
            @Result(column = "update_time", property = "updateTime"),
    })
    @Select("select * from setmeal ")
    public List<SetmealDto> list(String name);



    @Update("<script>" +
            "update setmeal set status = #{status} where id in " +
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    public void updateStatus(Integer status, List<Long> ids);



    @Delete("<script>" +
            "delete from setmeal where id in " +
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>" 
    )
    public void delete(List<Long> ids);


    @Select("<script>" +
            "select count(*) from setmeal where id in " +
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            " and status = 1" +
            "</script>"
    )
    public Integer getnumberByStatus(List<Long> ids);

    @Results({
            @Result(column = "category_id", property = "categoryId"),
    })
    @Select("select * from setmeal where id = #{id}")
    public Setmeal getById(Long id);

    @Select("select * from setmeal where category_id = #{categoryId} and status = #{status}")
    public List<Setmeal> getSetmealByCategoryId(Long categoryId, Integer status);

}
